import java.awt.event.ActionEvent;

public class SqrListener extends AnswerListenerAbstract{

    public static final int SQ = 0, SQRT = 1, POWN1 = 2, NEGATE = 3;
    int stat;
    Register register;
    void setStat(int i) {
        stat = i;
    }

    int getStat() {
        return stat;
    }

    public SqrListener(Register r, AnswerLabel a, int i)
    {
        register = r;
        setAnswer(a);
        stat = i;
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        double d= 0.0;
        if(getStat() == SQ) {
            d = Double.parseDouble(getAnswer().getText());
            d *= d;
        }else if(getStat() == SQRT) {
            d = Double.parseDouble(getAnswer().getText());
            d = Math.sqrt(d);
        }else if(getStat() == POWN1) {
            d = 1 / Double.parseDouble(getAnswer().getText());
        }else if(getStat() == NEGATE) {
            d =  -1.0 * Double.parseDouble(getAnswer().getText());
        }
        getAnswer().loadDouble(d);
        getAnswer().setStatus(AnswerLabel.EXPLICT);
    }
}
